<?php
	include_once("../../globals.php");
	include_once("$srcdir/api.inc");
	include_once("$srcdir/forms.inc");
	global $num_forms;
	
	
	$_SESSION['num_forms'] = 1;
	
	/*echo "<pre>";
		print_r($_REQUEST);
	echo "<pre>";*/
	
	$form_id = $_REQUEST['id'];
	$form_name = $_REQUEST['formname'];
	
	/*if($form_id){
		$query = "SELECT count(*) num FROM forms WHERE encounter = $encounter and form_id = $form_id;";
		$res = sqlStatement($query);
		$row = sqlFetchArray($res);
		$past_info = $row['num'];
		//$_SESSION['num_forms'] = intval($past_info) + 1;
		if(intval($past_info)>0){
			$query = "SELECT * FROM forms WHERE encounter = $encounter and form_id = $form_id;";
			$res = sqlStatement($query);
			$row = sqlFetchArray($res);
			$formsid[] = $row['form_id'];
		}else{
			//$_SESSION['num_forms'] = 1;
		}
		
	}
	
	
	$query = "SELECT count(*) num FROM forms WHERE encounter = $encounter and formdir = \"$form_name\";";
	//echo $query;
	$res = sqlStatement($query);
	$row = sqlFetchArray($res);
	$past_info = $row['num'];
	if($past_info>0){
		$query = "SELECT * FROM forms WHERE encounter = $encounter and formdir = \"$form_name\";";
		//echo $query;
		$res = sqlStatement($query);
		while ($row = sqlFetchArray($res)){
			$formsid[] = $row['form_id'];
		}
	}*/
	
	/*echo "<pre>";
		echo count($formsid);
	echo "</pre>";*/
	
	
	if( $form_id ) {
		$where_clause = '';
		$query = "Select * FROM form_pupillometry WHERE id = $form_id OR form_related = $form_id ";
		/*foreach ( $formsid as  $form_id){
			if( $where_clause !=''){
				$where_clause .= ' OR ';
				
			}
			$where_clause .= " forms_id = $form_id ";
		}*/
		$query .= $where_clause . " order by scheduled asc ";
		//echo $query;
		$forms_info = sqlStatement($query);
		$res = sqlStatement($query);
		while($row = sqlFetchArray($res)){
			$_SESSION['num_forms'] = intval($_SESSION['num_forms']) + 1;
		}
	}
	
	function selected($actual, $val){
		if( intval($actual) == intval($val) ){
			return " selected ";
		}
	}

	
?>
<html> 
	<head>
		<link rel="stylesheet" href="../../forms/pupillometry/tables.css" type="text/css">
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
		<script type='text/javascript' src='../../forms/pupillometry/functions.js'></script>
	</head>
	<body>  
		<h1><p class='titulo'> Pupillometry</p></h1>
		<form id='theform' name='theform' action=''>
			<?php 
			if( intval($_SESSION['num_forms']) > 0 ){
				include 'pupillometry_treatementEyeOnly_loaded.html' ;
				include 'externalOcular_Exam_treatementEyeOnly_loaded.html' ;
				include 'SlitLampExamination_loaded.html' ;
				include 'BestCorrectedVisualAcuity_loaded.html' ;
				include 'Gonioscopy_loaded.html' ;
				include 'AnteriorChamberDepth_loaded.html' ;
				include 'Dilated Fundus Examination_loaded.html' ;
			}else{
				include 'pupillometry_treatementEyeOnly.html' ;
				include 'externalOcular_Exam_treatementEyeOnly.html' ;
				include 'SlitLampExamination_loaded.html' ;
				include 'BestCorrectedVisualAcuity.html' ;
				include 'Gonioscopy.html' ;
				include 'AnteriorChamberDepth.html' ;
				include 'Dilated Fundus Examination.html' ;
			}
			?>	
			<input type='hidden' name='save_type' id='save_type' value='save_new'></input>
			<input type='hidden' name='save_values' id='save_values'></input>
			<input type='hidden' name='id' id='id' value='<?php echo $form_id;?>'></input>
			<input type='hidden' name='pid' id='pid' value='<?php echo $_SESSION['pid'];?>'></input> 
			
		</form>
		<input class='css_button' type='button' id='save_btn' name='save_btn' onclick='submit_form("s");' value='<?php echo xl('Save');?>'></input>
		<input class='css_button' type='button' id='save_btn2' name='save_btn2' onclick='submit_form("e");' value='<?php echo xl('Save Old');?>'></input>
	</body>
</html> 